import java.util.LinkedList;
public class MyQueue {
    static  class Node{
        public int val;
        public Node next;
        public Node(int val){
            this.val = val;
        }
    }
    public Node head;//队列的头
    public Node tail;//队列的尾

    //1.入队offer
    public void offer(int val){
        Node node = new Node(val);
        if(head == null){
            head = node;
            tail = node;
        }else{
            tail.next = node;
            tail = tail.next;
        }
    }
    //2.出队poll
    public int poll(){
        if(head == null){
            return -1;
        }
        int oldVal = head.val;
        if(head.next == null){
            head = tail = null;
        }else{
            head = head.next;
        }
        return oldVal;
    }
    //3.查看当前队头元素peek
    public int peek(){
        if(head == null){
            return -1;
        }
        return head.val;
    }

    public static void main(String[] args) {
        java.util.Queue<Integer> queue = new LinkedList<>();
        queue.offer(1);
        queue.offer(3);
        queue.offer(5);
        queue.offer(7);
        System.out.println(queue.size());
        System.out.println(queue.peek());
        queue.poll();
        System.out.println(queue.poll());
    }
}
